﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;
using System.Dynamic;
using System.IO;
namespace UI
{
    public partial class develop_wx : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //CreateMenu();

        }
        private void CreateMenu()
        {
            WeiXin wx = new WeiXin();
            StreamReader stream = new StreamReader("E:/www/yixiaoke(t+0)/menu.txt");
            string menu = stream.ReadToEnd();
            stream.Close();
            dynamic info = GetConfig();
            string code = wx.HttpPost("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + info.Token, menu);
            Commons.Log2(code);
        }

        public static dynamic GetConfig()
        {
            WeiXin wx = new WeiXin();
            string token = wx.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxeaaac23155345f7b&secret=c8ea16461e6d8aba4bc55f417b2a2c81", "");
            Commons.Log2(token);
            token = wx.ConvertJson(token).access_token;
            string ticket = GetTickect(token);
            ticket = wx.ConvertJson(ticket).ticket;
            dynamic config = new ExpandoObject();
            config.Token = token;
            config.Ticket = ticket;
            return config;

        }
        public static string GetTickect(string access_token)
        {
            WeiXin wx = new WeiXin();
            var url = string.Format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi", access_token);
            return wx.HttpGet(url, "");
        }
    }
}